﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BestLifePOS_Core.DomainObjects;
using BestLifePOS_Core.Data.Fascade;
using System.Data.SqlClient;

namespace BestLifePOS_PresentationLayer
{
    public partial class frmDisposalDamage : Form
    {
        public frmDisposalDamage()
        {
            InitializeComponent();
        }
        
        private Disposal CollectDisposalFigures() {
       
            try
            {
                Disposal Lvdis = new Disposal();
                Lvdis.Dis_Id = txtDisId.Text;
                Lvdis.PL_Id = txtPLID.Text;
               // Lvdis.PL_Id = txtProName.Text;
                Lvdis.Qty = Convert.ToDecimal(txtQty.Text);
                Lvdis.Description = txtDes.Text;
                Lvdis.Status = cmbStat.Text;
                Lvdis.User_Id = "1";
                Lvdis.User_Modify = "1";
                Lvdis.Date_Create = System.DateTime.Now;
                Lvdis.Last_Modify = System.DateTime.Now;
               // Lvdis.Total = "";
               

                return Lvdis;
            }
            catch(Exception) {
                return null;
            }
        }

        private int SaveButton()
        {
            Disposal LvDis = CollectDisposalFigures();
            if (LvDis != null)
            {
                return DisposalDAO.SaveDispo(LvDis);
            }
            else
            {
                return 0;
            }
        }

        public object Lvdis { get; set; }

        private void label94_Click(object sender, EventArgs e)
        {

        }

        private void btnDispoSave_Click(object sender, EventArgs e)
        {
             int result = SaveButton();
            if (result != 0)
            {
                MessageBox.Show("DISPOSAL WAS SUCCESFULLY SAVED");
            } 

        }

        private void txtProName_TextChanged(object sender, EventArgs e)
        {

        }   

        private void cmbPLId_SelectedIndexChanged(String connectionsrting)
        {
               
        }

        private void cmbStat_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void cmbPLId_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void TxtDes_TextChanged(object sender, EventArgs e)
        {

        }

        private void richTextBox1_TextChanged(object sender, EventArgs e)
        {


        }

        private void button34_Click(object sender, EventArgs e)
        {
            ClearAL();
        }

        private  Disposal  ClearAL()
        {

            Disposal LvdisD = new Disposal();

            txtDisId.Clear();
            txtPLID.Clear();
            txtProName.Clear();
            txtQty.Clear();
            txtDes.Clear();
           
            return LvdisD;
        }

        private void btnSubID_Click(object sender, EventArgs e)
        {
            SubIDSrhGRd();
        }

        private void SubIDSrhGRd()
        {
            DataTable GvSubCatData = new DataTable(); 

            GvSubCatData.Columns.Add("Diposal Id");
            GvSubCatData.Columns.Add("Product Id");
            GvSubCatData.Columns.Add("Product Name");
            GvSubCatData.Columns.Add("Description");

            DataTable GvSubCatDataAD = new DataTable();

            GvSubCatDataAD.Columns.Add("Diposal Id");
            GvSubCatDataAD.Columns.Add("Product Id");
            GvSubCatDataAD.Columns.Add("Product Name");
            GvSubCatDataAD.Columns.Add("Description");

            GvSubCatData = DisposalDAO.GetDispoBySubId(txtSubId.Text);

            int counte = GvSubCatData.Rows.Count;

            for (int i = 0; i <= counte - 1; i++)
            {
                //for DispoBySub
                GvSubCatDataAD.Rows.Add(GvSubCatDataAD.NewRow());
                GvSubCatDataAD.Rows[GvSubCatDataAD.Rows.Count - 1][0] = GvSubCatData.Rows[i][0].ToString();
                GvSubCatDataAD.Rows[GvSubCatDataAD.Rows.Count - 1][1] = GvSubCatData.Rows[i][1].ToString();
                GvSubCatDataAD.Rows[GvSubCatDataAD.Rows.Count - 1][2] = GvSubCatData.Rows[i][2].ToString();
                GvSubCatDataAD.Rows[GvSubCatDataAD.Rows.Count - 1][3] = GvSubCatData.Rows[i][3].ToString();

            }

            dataGridView5.DataSource = GvSubCatDataAD;

        }

        private void txtSubId_TextChanged(object sender, EventArgs e)
        {

        }
             
   }
    
}
